<template>
  <img class="image-element" :src="imageUrl" @click="handlePreview" />
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'ImageElemnt',
  props: {
    payload: {
      type: Object,
      required: true
    },
    message: {
      type: Object,
      required: true
    },
    imageArr: {
      type: Array,
      required: false,
      default: []
    }
  },
  computed: {
    ...mapGetters(['imgUrlList']),
    imageUrl() {
      let url;
      if(this.payload.imageInfoArray){
         url = this.payload.imageInfoArray[1].imageUrl
      }else{
        // 历史记录
         url = this.payload.ImageInfoArray[1].URL
      }
     
      if (typeof url !== 'string') {
        return ''
      }
      return url.slice(0, 2) === '//' ? `https:${url}` : url
    },
  },
  methods: {
    handlePreview() {
      // this.$bus.$emit('image-preview', {
      //   url: this.payload.imageInfoArray[0].url
      // })
      let curimg=this.imageUrl.split('?')[0]
      console.log(this.imageUrl)
      console.log(this.imageArr)
      this.$wx.previewImage({
        current: curimg, // 当前显示图片的http链接
        urls: this.imageArr
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.image-element{
  max-width: 2.4rem;
  border-radius: .026667rem;
}
</style>
